if(!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.servers.nodeProps.NodeProperties")) {
    tibco.admin.Main.loadResource("tibco/admin/enterpriseAssets/servers/nodeProps/jss/jss.xml", "tibco.admin", "jss900E", "ljss", false);
    jsx3.Class.defineClass(
            'tibco.admin.enterpriseAssets.servers.nodeProps.NodeProperties', // full name of the class to create
            jsx3.gui.Block, //  extends jsx3.lang.Object
            null, // dose not implements any interfaces
            function(nodeProperties) {
                nodeProperties.prototype.nodeName = null;
                nodeProperties.prototype.firstCall = true;

                nodeProperties.prototype.subscribeAll = function() {
                    this.clearAllProperties();
                    var me = this;
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.servers.EventID.ADD_STARTED, me, me.addNewNode);
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.servers.EventID.NODE_SELECTED, me, me.populateAdminNodeProperties);
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.servers.EventID.NODE_REFRESHED, me, me.clearAllProperties);
                    this.addMode = false;
                }

                nodeProperties.prototype.clearAllProperties = function() {
                    var textboxes = this.getDescendantsOfType(jsx3.gui.TextBox);
                    var buttons = this.getDescendantsOfType(jsx3.gui.Button)
                    for(var i = 0; i < buttons.length; i++) {
                        if(buttons[i].getName() == "btnEditNode_900E")
                            buttons[i].setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                        else
                            buttons[i].setDisplay(jsx3.gui.Block.DISPLAYNONE, true)
                    }
                    for(var i = 0; i < textboxes.length; i++) {
                        var lbl = textboxes[i].getParent().getChild(1);
                        textboxes[i].setValue("").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        if(textboxes[i].getColor() == "yellow")
                            textboxes[i].setColor("#FFFFFF");
                        lbl.setText("", true).setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    }
                    this.getDescendantOfName("sltHostName900E").setDisplay(jsx3.gui.Block.DISPLAYNONE, true)
                            .getParent().getChild(1).setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setText("", true);
                    this.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                }

                nodeProperties.prototype.populateAdminNodeProperties = function(objEvent) {
                    this.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    if(this.handler.isInEditMode()) {
                        return;
                    }
                    this.nodeName = objEvent.nodeName;
                    this.callgetAdminNodeConfiguration(objEvent);
                }

                nodeProperties.prototype.editNodeParameters = function(button) {
                    this.handler.beginEdit();
                    this.passedItems = {};
                    var buttonPane = button.getParent();
                    buttonPane.getChild("btnSaveNode_900E").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    buttonPane.getChild("btnCancelNode_900E").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true)
                    button.setDisplay(jsx3.gui.Block.DISPLAYNONE, true)
                    var textboxes = this.getDescendantsOfType(jsx3.gui.TextBox, false);
                    for(var i = 0; i < textboxes.length; i++) {
                        if(textboxes[i].getName() != "txtTibcoHome900E" && textboxes[i].getName() != "txtNodeName_900E")
                            textboxes[i].setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).
                                    getParent().getChild(1).setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    }

                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.servers.EventID.DISABLED_REFRESH;
                    tibco.admin.PubSub.publish(msg);
                }

                nodeProperties.prototype.addNewNode = function(objEvent) {
                    this.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    this.handler.beginEdit();
                    this.passedItems = {"txtNodeName_900E":false,
                        "txtNamingPort_900E":false,
                        "txtHttpPort_900E":false,
                        "txtTibcoHome900E":false
                    };
                    this.addMode = true;
                    this.getDescendantOfName("btnSaveNode_900E").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    this.getDescendantOfName("btnCancelNode_900E").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.getDescendantOfName("btnAddNewNode_900E").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    this.getDescendantOfName("btnCancelNewNode_900E").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true)
                    this.getDescendantOfName("btnEditNode_900E").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    var textboxes = this.getDescendantsOfType(jsx3.gui.TextBox, false);
                    for(var i = 0; i < textboxes.length; i++) {
                        textboxes[i].setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue("");
                        textboxes[i].getParent().getChild(1).setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        if(textboxes[i].getName() != "txtTibcoHome900E") {
                            textboxes[i].setEnabled(jsx3.gui.Form.STATEENABLED, true)
                        }
                        else {
                            textboxes[i].setEnabled(jsx3.gui.Form.STATEDISABLED, true)
                        }
                    }
                    var select = this.getDescendantOfName("sltHostName900E");
                    select.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue("")
                            .getParent().getChild(1).setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    if(!select.getXML() || select.getXML().selectNodes("//record").getLength() == 0) {
                        this.callgetConnectedManagementDaemons();
                    }
                    select.setValue("");
                }

                nodeProperties.prototype.cancelNewNode = function() {
                    this.handler.endEdit();
                    this.clearAllProperties();
                    this.addMode = false;
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.servers.EventID.ADD_OVER;
                    msg.isDisabled = false;
                    tibco.admin.PubSub.publish(msg);

                    var msg1 = new Object();
                    msg1.subject = tibco.admin.enterpriseAssets.servers.EventID.ENABLE_REFRESH;
                    tibco.admin.PubSub.publish(msg1);
                }

                nodeProperties.prototype.resetEditNodeParameters = function(button, saved) {
                    this.handler.endEdit();
                    // add by Jim
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.servers.EventID.ENABLE_REFRESH;
                    tibco.admin.PubSub.publish(msg);
                    var buttonPane = button.getParent();
                    buttonPane.getChild("btnSaveNode_900E").setEnabled(jsx3.gui.Form.STATEDISABLED, true).
                            setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    buttonPane.getChild("btnEditNode_900E").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true)
                    buttonPane.getChild("btnCancelNode_900E").setDisplay(jsx3.gui.Block.DISPLAYNONE, true)
                    var textboxes = this.getDescendantsOfType(jsx3.gui.TextBox, false);
                    for(var i = 0; i < textboxes.length; i++) {
                        var lbl = textboxes[i].getParent().getChild(1);
                        if(!saved) {
                            textboxes[i].setValue(lbl.getText()).setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        }
                        else {
                            lbl.setText(textboxes[i].getValue(), true);
                            textboxes[i].setDisplay(jsx3.gui.Block.DISPLAYNONE, true)
                        }
                        lbl.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);

                    }
                    var select = this.getDescendantOfName("sltHostName900E").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    var lbl = select.getParent().getChild(1).setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    if(saved)
                        lbl.setText(select.getText(), true);
                    else
                        select.setValue(lbl.getText());

                }

                nodeProperties.prototype.callgetAdminNodeConfiguration = function(objEvent) {
                    if(this.nodeName == null)
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@lbl_Error_900E"), tibco.admin.Main.getServer().getDynamicProperty("@lbl_NoSelected_900E"));

                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/nodeProps/rules/getAdminNodeProperties.xml",
                            "getAdminNodeConfiguration",
                            "get admin nodes configuration.");
                    objService.hostName = objEvent.hostName;
                    objService.nodeName = this.nodeName;
                    objService.tibcoHome = objEvent.tibcoHome;
                    //subscribe and call
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.ongetAdminNodeConfigurationSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getAdminConfigurationEndpointURL())
                    objService.doCall();
                };

                nodeProperties.prototype.ongetAdminNodeConfigurationSuccess = function(objEvent) {
                    this.getDescendantOfName("btnEditNode_900E").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    this.tibcoHome = objEvent.target.tibcoHome;
                    this.hostName = objEvent.target.hostName;
                };

                nodeProperties.prototype.callupdateAdminNodeDetails = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/nodeProps/rules/updateAdminNodePropertiesRules.xml",
                            "updateAdminNodeDetails",
                            "update admin nodes configuration.");
                    //subscribe and call
                    objService.hostName = this.getDescendantOfName("sltHostName900E").getText();
                    objService.tibcoHome = this.getDescendantOfName("txtTibcoHome900E").getValue();
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onupdateAdminNodeDetailsSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getAdminConfigurationEndpointURL())
                    objService.doCall();
                };

                nodeProperties.prototype.onupdateAdminNodeDetailsSuccess = function(objEvent) {
                    // add by Jim
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.servers.EventID.ENABLE_REFRESH;
                    tibco.admin.PubSub.publish(msg);
                    this.resetEditNodeParameters(tibco.admin.Main.getServer().getJSXByName('btnSaveNode_900E'), true);

                };

                nodeProperties.prototype.callcreateAdminNode = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/nodeProps/rules/createAdminNode.xml",
                            "createAdminNode",
                            "create an admin node.");
                    //subscribe and call
                    objService.hostName = this.getDescendantOfName("sltHostName900E").getText();
                    objService.tibcoHome = this.getDescendantOfName("txtTibcoHome900E").getValue();
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.oncreateAdminNodeSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getAdminConfigurationEndpointURL())
                    objService.doCall();
                };

                nodeProperties.prototype.oncreateAdminNodeSuccess = function(objEvent) {
                    this.cancelNewNode();
                };

                nodeProperties.prototype.callgetConnectedManagementDaemons = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/servers/nodeProps/rules/getConnectedMachinesRules.xml",
                            "getConnectedManagementDaemons",
                            "get connected management daemons.");
                    //subscribe and call
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagementDaemonEndpointURL());
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.ongetConnectedManagementDaemonsSuccess);
                    objService.doCall();
                };

                nodeProperties.prototype.ongetConnectedManagementDaemonsSuccess = function(objEvent) {
                    var select = this.getDescendantOfName("sltHostName900E");
                    select.repaint();
                    select.setValue(select.getParent().getChild(1).getText());
                };

                nodeProperties.prototype.setTibcoHome = function(selectBox) {
                    var record = selectBox.getXML().selectSingleNode("//record[@jsxid='" + selectBox.getValue() + "']")
                    var tibcoHomeText = this.getDescendantOfName("txtTibcoHome900E");
                    tibcoHomeText.setValue(record.getAttribute("tibcoHome"));
                    this.passedItems[tibcoHomeText.getName()] = true;
                    this.enableSaveBtn();
                }

                nodeProperties.prototype.validateField = function(obj, strValue) {
                    this.passedItems[obj.getName()] = tibco.admin.util.Validation.doValidateNotEmptyNoWhSpace(obj, strValue);
                    this.enableSaveBtn();
                }
                nodeProperties.prototype.enableSaveBtn = function() {
                    var allPassed = true;
                    for(var item in this.passedItems) {
                        if(!this.passedItems[item]) allPassed = false;
                    }
                    if(allPassed) {
                        this.getDescendantOfName(this.addMode?"btnAddNewNode_900E":"btnSaveNode_900E").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    }
                    else {
                        this.getDescendantOfName(this.addMode?"btnAddNewNode_900E":"btnSaveNode_900E").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    }
                }

            });
}